import urllib.request
import re
import base64

# url = 'http://www.meipai.com/media/944023881'

def reverse(string):
    return string[::-1]

def getHex(param1):
    return {
            'str': param1[4:],
            'hex': reverse(param1[0:4])
            }

def getDec(param1):
    loc2 = str(int(param1, 16))
    return {
            'pre': list(loc2[0:2]),
            'tail': list(loc2[2:])
            }

def mysubstr(param1, param2):
    loc1 = int(param2[0])
    loc2 = int(param2[1])
    return param1[0:loc1] + param1[loc1+loc2:]

def getPos(param1, param2):
    loc1 = int(param2[0])
    loc2 = int(param2[1])
    param2[0] = len(param1) - loc1 - loc2
    return param2

def decode(string):
    dict2 = getHex(string)
    #print(dict2)
    dict3 = getDec(dict2['hex'])
    #print(dict3)
    str4 = mysubstr(dict2['str'], dict3['pre'])
    str5 = mysubstr(str4, getPos(str4, dict3['tail']))
    return base64.decodebytes(str5.encode(encoding="utf-8"))

def Decode(string):
    return decode(string).decode()
